<?php
/**
 * Created by PhpStorm.
 * User: iceberg
 * Date: 2018-10-09
 * Time: 13:44
 */

namespace app\base\controller;


use app\service\CategoryService;
use think\Controller;

class Category extends Controller
{
    //分类服务
    private $categoryService;

    //初始化方法
    public function initialize()
    {
        $this->categoryService = new CategoryService();
    }

    //显示列表
    public function index()
    {
        $this->assign('count', $this->categoryService->count());
        $this->assign('list', $this->categoryService->page());
        return $this->fetch();
    }

    //显示创建页面
    public function create()
    {
        $category = $this->categoryService->getList();
        $lst_category = get_tree($category);
        //dump(get_tree($category));die;
        $this->assign('category', $lst_category);
        return $this->fetch();
    }

    //保存数据
    public function save()
    {
        return $this->categoryService->save();
    }

    //显示编辑界面
    public function edit($id)
    {
        $category = $this->categoryService->getList();
        $lst_category = get_tree($category);
        $this->assign('category', $lst_category);
        $this->assign('info', $this->categoryService->edit($id));
        return $this->fetch();
    }

    //更新
    public function update()
    {
        return $this->categoryService->update();
    }

    //删除
    public function delete($id)
    {
        return $this->categoryService->delete($id);
    }
}